package com.rboat.blog.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.rboat.common.utils.DateUtils;
import com.rboat.common.utils.StringUtils;
import com.rboat.framework.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rboat.blog.mapper.BlogArticleMapper;
import com.rboat.blog.domain.BlogArticle;
import com.rboat.blog.service.IBlogArticleService;
import com.rboat.common.core.text.Convert;

/**
 * 文章Service业务层处理
 * 
 * @author rboat
 * @date 2019-11-05
 */
@Service
public class BlogArticleServiceImpl implements IBlogArticleService 
{
    @Autowired
    private BlogArticleMapper blogArticleMapper;

    /**
     * 查询文章
     * 
     * @param id 文章ID
     * @return 文章
     */
    @Override
    public BlogArticle selectBlogArticleById(String id)
    {
        return blogArticleMapper.selectBlogArticleById(id);
    }

    /**
     * 查询文章列表
     * 
     * @param blogArticle 文章
     * @return 文章
     */
    @Override
    public List<BlogArticle> selectBlogArticleList(BlogArticle blogArticle)
    {
        return blogArticleMapper.selectBlogArticleList(blogArticle);
    }

    /**
     * 新增文章
     * 
     * @param blogArticle 文章
     * @return 结果
     */
    @Override
    public int insertBlogArticle(BlogArticle blogArticle)
    {
        blogArticle.setId(StringUtils.getPrimaryKey());
        blogArticle.setArticlePublishTime(DateUtils.getNowDate());
        blogArticle.setCreateBy(ShiroUtils.getLoginName());
        blogArticle.setArticleMasterId(ShiroUtils.getUserIdStr());
        return blogArticleMapper.insertBlogArticle(blogArticle);
    }

    /**
     * 修改文章
     * 
     * @param blogArticle 文章
     * @return 结果
     */
    @Override
    public int updateBlogArticle(BlogArticle blogArticle)
    {
        return blogArticleMapper.updateBlogArticle(blogArticle);
    }

    /**
     * 删除文章对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBlogArticleByIds(String ids)
    {
        return blogArticleMapper.deleteBlogArticleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除文章信息
     * 
     * @param id 文章ID
     * @return 结果
     */
    @Override
    public int deleteBlogArticleById(String id)
    {
        return blogArticleMapper.deleteBlogArticleById(id);
    }
}
